#ifndef CLINE2D_H_
#define CLINE2D_H_

#include "cvector2d.h"
#include "../exception/cintersectnotexistexception.h"

/**
 * CLine2D - straight line in a plane (in general/implicit respresentation)
 * @author Michal Rost
 * @date 20.06.2007
 */
template <typename T>
class CLine2D : public CObject {
public:
  CLine2D();
  CLine2D(const CLine2D<T> &l);
  CLine2D(const CVector2D<T> &normal, T originDist);
  CLine2D(T normalX, T normalY, T originDist);
  CLine2D(const CVector2D<T> &p1, const CVector2D<T> &p2);
  bool operator == (const CLine2D<T> &l) const;
  bool operator != (const CLine2D<T> &l) const;
  void set(const CVector2D<T> &normal, T originDist);
  bool isPointOnLine(const CVector2D<T> &p);
  bool isIntersecting(const CVector2D<T> &p1, const CVector2D<T> &p2);
  bool isIntersecting(const CLine2D<T> &l);
  bool isParalell(const CLine2D<T> &l);
  CVector2D<T> findIntersection(const CLine2D<T> &l);
  CVector2D<T> getNormal() const;
  T getOriginDist() const;
  T pointDist(const CVector2D<T> &p);
  T lineDist(const CLine2D<T> &l);
  static string getClassName() {
    static const string CLASS_NAME = "CLine2D";
    return CLASS_NAME;
  }
protected:
  CVector2D<T> normal;
  T originDist;
  void copyFrom(const CLine2D<T> &l);
  void init(CVector2D<T> normal, T dist);
  T calculateIntersectDenominator(const CVector2D<T> &n1,
                                  const CVector2D<T> &n2);
};

#endif
